package northwind.service;

import java.util.Collection;

import northwind.model.Category;
import northwind.model.Product;
import northwind.repository.ProductRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {

    private ProductRepository productRepository;

    @Autowired
    public ProductServiceImpl(ProductRepository productRepository) {
        super();
        this.productRepository = productRepository;
    }

    @Override
    public Collection<Category> findCategories() throws DataAccessException {
        return this.productRepository.findAllCategory();
    }

    @Override
    public Category findCategoryById(final int id) throws DataAccessException {
        return this.productRepository.findCategoryById(id);
    }

    @Override
    public int createCategory(String name, String description)
            throws DataAccessException {
        return this.productRepository.createCategory(name, description);
    }

    @Override
    public Collection<Product> findAllProduct() throws DataAccessException {

        return this.productRepository.findAllProduct();
    }

    @Override
    public Collection<Product> findAllProductByCategory(int categoryID)
            throws DataAccessException {
        return this.productRepository.findAllProductByCategory(categoryID);
    }

}
